Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add tests for IEEE 754-2019 compliance #6571

Merged
merged 19 commits into from
Apr 9, 2025

Conversation

anandkaranubc
Copy link
Contributor

Progresses #365

Description

What is the purpose of this pull request?

This pull request:

  • Adds all the tests for testing special cases of log*

Related Issues

Does this pull request have any related issues?

This pull request:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@stdlib-bot stdlib-bot added Math Issue or pull request specific to math functionality. Needs Review A pull request which needs code review. labels Apr 5, 2025
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@anandkaranubc
Copy link
Contributor Author

image

All checked!

@Planeshifter
Copy link
Member

Planeshifter commented Apr 5, 2025

@anandkaranubc Per failing CI checks, looks like our log10 might not behave as expected for -0. Would you mind taking a look, please?

@anandkaranubc
Copy link
Contributor Author

anandkaranubc commented Apr 5, 2025

Haha, was in the middle of writing the reason :)

Oops, there is a bug. log2 and log10 don't return NINF when x = -0.0. But it works in C.

Mainly because of no type casting on hx in JS.

toWords.assign( x, WORDS, 1, 0 );
hx = WORDS[ 0 ];
lx = WORDS[ 1 ];
k = 0|0; // asm type annotation
if ( hx < HIGH_MIN_NORMAL_EXP ) {
// Case: x < 2**-1022
if ( ( (hx&ABS_MASK) | lx ) === 0 ) {
return NINF;
}

hx still remains a "huge" positive number here and isn't less than HIGH_MIN_NORMAL_EXP

But in C,

Typecasting it back again in int32_t makes it negative again.

xc = x;
stdlib_base_float64_to_words( xc, &hx, &lx );
ihx = (int32_t)hx;
k = 0;
if ( ihx < HIGH_MIN_NORMAL_EXP ) {
// Case: x < 2**-1022
if ( ( ( ihx & STDLIB_CONSTANT_FLOAT64_HIGH_WORD_ABS_MASK ) | lx ) == 0 ) {
return STDLIB_CONSTANT_FLOAT64_NINF;
}

cc: @Planeshifter @kgryte

@anandkaranubc anandkaranubc added the Tests Pull requests specifically adding tests. label Apr 9, 2025
@kgryte
Copy link
Member

kgryte commented Apr 9, 2025

@anandkaranubc For L22, if the condition assumes ihx, then we can modify to

if ( (hx|0) < HIGH_MIN_NORMAL_EXP ) { 
 	// Case: x < 2**-1022 
 	if ( ( (hx&ABS_MASK) | lx ) === 0 ) { 
 		return NINF; 
 	} 

@anandkaranubc
Copy link
Contributor Author

@kgryte Thanks for the reply!

Can I do hx = WORDS[ 0 ] | 0; instead?

anandkaranubc and others added 14 commits April 9, 2025 00:15
PR-URL: stdlib-js#6590

Reviewed-by: Philipp Burckhardt <[email protected]>
Signed-off-by: stdlib-bot <[email protected]>
PR-URL: stdlib-js#6608
Co-authored-by: Athan Reines <[email protected]>
Reviewed-by: Athan Reines <[email protected]> 
Signed-off-by: Athan Reines <[email protected]>
PR-URL: stdlib-js#6596
Closes: stdlib-js#6588
Co-authored-by: Athan Reines <[email protected]>
Reviewed-by: Athan Reines <[email protected]> 
Signed-off-by: Mahfuza Humayra Mohona <[email protected]>
Signed-off-by: Athan Reines <[email protected]>
PR-URL: stdlib-js#6597
Ref: stdlib-js#365
Reviewed-by: Athan Reines <[email protected]>
Signed-off-by: Karan Anand <[email protected]>
PR-URL: stdlib-js#5639
Closes: stdlib-js/metr-issue-tracker#20
Co-authored-by: Athan Reines <[email protected]>
Reviewed-by: Athan Reines <[email protected]> 
Signed-off-by: Muhammad Haris <[email protected]>
Signed-off-by: Athan Reines <[email protected]>
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@kgryte
Copy link
Member

kgryte commented Apr 9, 2025

@anandkaranubc Actually, are we sure the issue is with hx here? Given

x will be positive once going to toWords. Hence, the sign-bit of the high word will be zero. In which case, hx and hx|0 should be the same value.

@anandkaranubc
Copy link
Contributor Author

/stdlib merge

@stdlib-bot stdlib-bot added the bot: In Progress Pull request is currently awaiting automation. label Apr 9, 2025
@kgryte
Copy link
Member

kgryte commented Apr 9, 2025

@anandkaranubc Ah, I see. The special case is -0. In which case, yes, you are right. Based on the code, it should be reasonable to do

hx = WORDS[ 0 ] | 0; // asm type annotation

@stdlib-bot stdlib-bot removed the bot: In Progress Pull request is currently awaiting automation. label Apr 9, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Apr 9, 2025

Coverage Report

Package Statements Branches Functions Lines
math/base/special/ln $\color{red}370/382$
$\color{green}+96.86\%$
$\color{red}25/28$
$\color{green}+89.29\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{red}370/382$
$\color{green}+96.86\%$
math/base/special/lnf $\color{red}372/376$
$\color{green}+98.94\%$
$\color{red}30/32$
$\color{green}+93.75\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{red}372/376$
$\color{green}+98.94\%$
math/base/special/log $\color{green}171/171$
$\color{green}+100.00\%$
$\color{green}5/5$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}171/171$
$\color{green}+100.00\%$
math/base/special/log10 $\color{green}307/307$
$\color{green}+100.00\%$
$\color{green}16/16$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}307/307$
$\color{green}+100.00\%$
math/base/special/log2 $\color{green}290/290$
$\color{green}+100.00\%$
$\color{green}16/16$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}290/290$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this PR.

@@ -132,7 +132,7 @@ function log10( x ) {

// Subnormal number, scale up x:
x *= TWO54;
hx = getHighWord( x );
hx = getHighWord( x ) | 0; // asm type annotation
Copy link
Contributor Author

@anandkaranubc anandkaranubc Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also updated this line accordingly to be consistent with upstream (and C) implementation.

Reference

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our C implementation:

xc *= TWO54;
stdlib_base_float64_get_high_word( xc, &hx );
ihx = (int32_t)hx;

@anandkaranubc
Copy link
Contributor Author

The failing test is unrelated to this PR.

@anandkaranubc anandkaranubc requested a review from kgryte April 9, 2025 07:42
@kgryte
Copy link
Member

kgryte commented Apr 9, 2025

@anandkaranubc I'll fix that up on develop now.

@kgryte
Copy link
Member

kgryte commented Apr 9, 2025

/stdlib merge

@stdlib-bot stdlib-bot added the bot: In Progress Pull request is currently awaiting automation. label Apr 9, 2025
@stdlib-bot stdlib-bot removed the bot: In Progress Pull request is currently awaiting automation. label Apr 9, 2025
@kgryte kgryte removed the Needs Review A pull request which needs code review. label Apr 9, 2025
Copy link
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kgryte kgryte merged commit c9cacbf into stdlib-js:develop Apr 9, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Math Issue or pull request specific to math functionality. Tests Pull requests specifically adding tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants